
package processors;

import containers.Groups;
import containers.TestsTaken;
import java.util.LinkedList;
import readers.QueryStringHandler;
import readers.UserReader;

/**
 * This creates a list of words that will be processed by the iPhone
 * @author Chris
 */
public class processorQuizWords extends processor {
    private String _errMsg;
    processorQuizWords(String query) {
        super(query);
        _errMsg = "[ERROR]";
    }
    
    @Override
    String process() {
        QueryStringHandler qsh = new QueryStringHandler(_queryString);
        String userName = qsh.getElement("username");
        String teacherName = qsh.getElement("TN");
        String groupName = qsh.getElement("GN");
        String testName = qsh.getElement("TID");
        
        if(userName == null || teacherName == null || groupName == null
                || testName == null) {
            return _errMsg;
        }
        LinkedList<String> words = new LinkedList<String>();
        
        if(!UserReader.getTest(teacherName, groupName, testName, words)) {
            words.clear();
            return _errMsg;
        }
        
        String results = "";//"<quiz>";
        while(!words.isEmpty()) {
            results += words.getFirst() + "\n";
                    //"<word>" + words.getFirst() + "</word>";
            words.removeFirst();
        }
        results += "";//"</quiz>";
        
        return results;
    }
}
